
var x = 0;
app.controller('kspCtrl',function($scope,$http){
	//点击小图切换图片
	$('.k_cd_lb img').each(function(i,e){
		$(e).click(function(){
			$('.k_cd_lb img').css('border','none');
			$(e).css('border','1px solid orange');
			$('.k_cd_ls img').attr('src',$(e).attr('src'));
			x=i;
		})
	});
	//上一张
	$('.k_cd_lb span').eq(0).click(function(){
		x--;
		if(x==-1){
			x=3;
		};
		$('.k_cd_lb img').css('border','none');
		$('.k_cd_lb img').eq(x).css('border','1px solid orange');
		$('.k_cd_ls img').attr('src',$('.k_cd_lb img').eq(x).attr('src'));
	});
	//下一张
	$('.k_cd_lb span').eq(1).click(function(){
		x++;
		if(x==4){
			x=0;
		};
		$('.k_cd_lb img').css('border','none');
		$('.k_cd_lb img').eq(x).css('border','1px solid orange');
		$('.k_cd_ls img').attr('src',$('.k_cd_lb img').eq(x).attr('src'));
	});
	//鼠标移入放大
	
	//
	$('.k_cd_ls').mouseenter(function(){
		$('.k_shops_big').show();
		$('.k_shops_zoom').show();
		$('.k_shops_big img').attr('src',$('.k_cd_ls img').attr('src'));
		
		$('.k_cd_ls').mousemove(function(e){
		var even = e || event;
		var x = even.clientX - ($('.k_shops_zoom').width())/2 - $('.k_cd_ls').offset().left;
		var y = even.clientY - ($('.k_shops_zoom').height())/2 - $('.k_cd_ls').offset().top;
		var maxX = $('.k_cd_ls').width() - $('.k_shops_zoom').width();
		var maxY = $('.k_cd_ls').height() - $('.k_shops_zoom').height();
		if(x < 0){
				x = 0;
			}
			if(x > maxX){
				x = maxX;
			}
			if(y < 0){
				y = 0;
			}
			if(y > maxY){
				y = maxY;
			}
			$('.k_shops_zoom').css({
				left:x+'px',
				top:y+'px'
			});
		var bigImgX = (x / maxX) * ($('.k_shops_big img').width() -  $('.k_shops_big').width());
			var bigImgY = (y / maxY) * ($('.k_shops_big img').height() - $('.k_shops_big').height() );
			$('.k_shops_big')[0].scrollLeft = bigImgX ;
			$('.k_shops_big')[0].scrollTop = bigImgY;
	})
		
	})
	$('.k_shops_zoom').mouseout(function(){
		$('.k_shops_big').hide();
		$('.k_shops_zoom').hide();
	});
	//评分
	function kScore(){
		var p1 = $(".k_cd_rbl span").text().substr(0,3);
		var p2 = $(".k_cd_rbl span").text().substr(0,3);
		var p3 = $(".k_cd_rbl span").text().substr(0,3);
		var pn = ((p1-0)+(p2-0)+(p3-0))/3;
		$('.k_cd_rd span').eq(1).text(pn+'分');
		console.log((pn/5)*100+'%');
		$(".k_cd_rs div").css('width',(pn/5)*100+'%')
	};
	kScore()
	//分类
	$('.k_shops_cul li').each(function(i,e){
		$(e).click(function(){
			$('.k_shops_cul li').css({
				'color':'#666666',
				'background':'none'
			})
			$(e).css({
				'color':'white',
				'background':'rgb(73,142,61)'
			})
		})
	})
	
	//
	$http.get('../php/k_crt.php?l=total').success(function(data){
		$scope.kshops = data;
		l = data.length;
	})
})
